//
//  RecommendCourseCell.m
//  Courses
//
//  Created by xxx on 15/1/5.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "RecommendCourseCell.h"
#import "UIImageView+WebCache.h"
#import "UILabel+AutoSize.h"

//@property (nonatomic, strong) NSString *courseId;
//@property (nonatomic, strong) NSString *courseName;
//@property (nonatomic, strong) NSString *teacherName;
//@property (nonatomic, strong) NSString *title;
//@property (nonatomic, strong) NSString *headPhotoUrl;
//@property (nonatomic, strong) NSString *favoritesNum;

@implementation RecommendCourseCell
{
    UILabel *_lblCourseName;
    UILabel *_lblTitle;
    UIView  *_viewBackgroundForLblTitle;
    UILabel *_lblTeacherName;
    UIImageView *_imgViewAvatar;
    UILabel *_lblCourseDescription;
    UILabel *_lblFavoritesNum;
    UILabel *_lblCoursefavoritesNum;
}

#define HEIGHT_L 18
#define HEIGHT_S 12

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (!self) return self;
    
    self.backgroundColor = nil;
    self.frame = AutoRectMake(0, 0, DEFAULT_WIDTH, 80, WTFAutoLayoutTypePic);
    
//    UIView *viewSeparator = [[UIView alloc] initWithFrame:CGRectMake(0, 0, AutoFloat(DEFAULT_WIDTH), 1)];
//    viewSeparator.backgroundColor = [WTFColors colorWithHexStr:@"666666"];
//    [self.contentView addSubview:viewSeparator];
    
    _imgViewAvatar = [[UIImageView alloc] initWithFrame:AutoRectMake(10, 10, 80, 60, WTFAutoLayoutTypeRaw)];
    _imgViewAvatar.layer.cornerRadius = 17;
    _imgViewAvatar.layer.masksToBounds = YES;
    _imgViewAvatar.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_imgViewAvatar];
    
    _lblTeacherName = [[UILabel alloc] initWithFrame:AutoRectMake(100, 10, 100, HEIGHT_L, WTFAutoLayoutTypeBar)];
    _lblTeacherName.font = [UIFont fontWithName:nil size:FONT_SIZE_TITLE];
    [self.contentView addSubview:_lblTeacherName];
    
    _lblTitle = [[UILabel alloc] initWithFrame:AutoRectMake(160, 10, 100, HEIGHT_L, WTFAutoLayoutTypeBar)];
    _lblTitle.font = [UIFont fontWithName:nil size:FONT_SIZE_SUBTITLE];
    _lblTitle.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_lblTitle];
    _viewBackgroundForLblTitle = [[UIView alloc] initWithFrame:_lblTitle.frame];
    _viewBackgroundForLblTitle.layer.cornerRadius = 3;
    _viewBackgroundForLblTitle.backgroundColor = [WTFColors defaultIconColor];
    [self.contentView addSubview:_viewBackgroundForLblTitle];
    _viewBackgroundForLblTitle.hidden = YES;
    
    _lblCourseName = [[UILabel alloc] initWithFrame:AutoRectMake(100, 10 + HEIGHT_L, DEFAULT_WIDTH - 105, HEIGHT_L, WTFAutoLayoutTypeBar)];
    _lblCourseName.font = [UIFont fontWithName:nil size:FONT_SIZE_TITLE];
    [self.contentView addSubview:_lblCourseName];
    
    _lblCourseDescription = [[UILabel alloc] initWithFrame:AutoRectMake(100, 10 + HEIGHT_L * 2, 300, HEIGHT_S, WTFAutoLayoutTypeBar)];
    _lblCourseDescription.font = [UIFont fontWithName:nil size:FONT_SIZE_CONTENT];
    [self.contentView addSubview:_lblCourseDescription];
    
    _lblFavoritesNum = [[UILabel alloc] initWithFrame:AutoRectMake(110, 10 + HEIGHT_L * 2 + HEIGHT_S, 150, HEIGHT_S, WTFAutoLayoutTypeBar)];
    _lblFavoritesNum.font = [UIFont fontWithName:nil size:FONT_SIZE_CONTENT];
    [self.contentView addSubview:_lblFavoritesNum];
    //添加观看小图标
    UIImageView* watchImage = [[UIImageView alloc]initWithFrame:AutoRectMake(100 - 2, 10 + HEIGHT_L * 2 + HEIGHT_S, 10, 10, WTFAutoLayoutTypeBar)];
    [watchImage setImage:[UIImage imageNamed:@"collectionImage.jpg"]];
    [self.contentView addSubview:watchImage];
    
    //
    _lblCoursefavoritesNum = [[UILabel alloc] initWithFrame:AutoRectMake(210, 10 + HEIGHT_L * 2 + HEIGHT_S, 150, HEIGHT_S, WTFAutoLayoutTypeBar)];
    _lblCoursefavoritesNum.font = [UIFont fontWithName:nil size:FONT_SIZE_CONTENT];
    [self.contentView addSubview:_lblCoursefavoritesNum];
    //添加收藏小图标
    UIImageView* collecTion = [[UIImageView alloc]initWithFrame:AutoRectMake(200 - 2, 10 + HEIGHT_L * 2 + HEIGHT_S, 10, 10, WTFAutoLayoutTypeBar)];
    [collecTion setImage:[UIImage imageNamed:@"watchImage.jpg"]];
    [self.contentView addSubview:collecTion];
    //
    return self;
}

- (void)setCourse:(Course *)course
{
    _course = course;
    
    [_imgViewAvatar sd_setImageWithURL:[NSURL URLWithString:course.teacherHeadPhotoUrl]];
    
    _lblTeacherName.text = course.teacherName;
    
    _lblTitle.text = course.teacherTitle;
    _viewBackgroundForLblTitle.hidden = YES;
    if (course.teacherTitle.length)
    {
        [_lblTitle autoSetSizeWithInWidth:100 preferedHeight:HEIGHT_L];
        _viewBackgroundForLblTitle.frame = _lblTitle.frame;
        _viewBackgroundForLblTitle.width += 6;
        _viewBackgroundForLblTitle.left -= 3;
        _viewBackgroundForLblTitle.hidden = NO;
        [self.contentView bringSubviewToFront:_lblTitle];
    }
    
    _lblCourseName.text = course.courseName;
    
    _lblCourseDescription.text = course.courseDescription;
    
    _lblFavoritesNum.text = course.favoritesNum;
    _lblCoursefavoritesNum.text = course.courseViewNum;
}

@end
